package com.tiemei.demo.unittest.mockito;

import static org.mockito.Mockito.*;

import java.awt.List;

import org.junit.Test;
import org.mockito.InOrder;

public class VerifyMethodInvokedOrder {

	@Test
	public void test1MockedObj() {
		// 1. mock
		List singleMock = mock(List.class);

		// 2. run
		singleMock.add("was added first");
		singleMock.add("was added second");

		// 3. verify
		InOrder inOrder = inOrder(singleMock);
		// following will make sure that add is first called with
		// "was added first, then with "was added second"
		inOrder.verify(singleMock).add("was added first");
		inOrder.verify(singleMock).add("was added second");
	}

	@Test
	public void testNMockedObj() {
		// 1. mock
		List firstMock = mock(List.class);
		List secondMock = mock(List.class);

		// 2. run
		firstMock.add("was called first");
		secondMock.add("was called second");

		// 3. verify
		InOrder inOrder = inOrder(firstMock, secondMock);
		// following will make sure that firstMock was called before secondMock
		inOrder.verify(firstMock).add("was called first");
		inOrder.verify(secondMock).add("was called second");
	}
}
